﻿using NBpn.Cfg;
using NBpn.Network;
using Xunit;

namespace NBpn.Test.Network
{
    using System.Collections;
    using System.Collections.Generic;

    public class BpnFixture
    {
        public void CreateConfiguration()
        {
            Configuration cfg = new Configuration();

            cfg.AddInputLinealNeuron();
            cfg.AddInputLinealNeuron();

            cfg.AddNeuronSigmoidalNeuronAtLayer(1);
            cfg.AddNeuronSigmoidalNeuronAtLayer(1);

            cfg.AddNeuronSigmoidalNeuronAtLayer(2);
            cfg.AddNeuron(2,new SigmoidalNeuron());

            cfg.AddOutputSigmoidalNeuronAtLayer();
            cfg.AddOutputNeuron(new SigmoidalNeuron());

            Bpn bpn = cfg.BuildNetwork();

            double[] output = bpn.GetOutput();

            double[] outputExpected = new double[] {0,0};

            bpn.RecalculateWeigths(outputExpected);

            Assert.NotNull(bpn);
        }

        public void ProcedimientoDeLaBPN() {

            Configuration cfg = new Configuration();

            cfg.SetGlobalError(0.001);

            cfg.AddInputLinealNeuron();
            cfg.AddInputLinealNeuron();

            cfg.AddNeuronSigmoidalNeuronAtLayer(1);
            cfg.AddNeuronSigmoidalNeuronAtLayer(1);

            cfg.AddNeuronSigmoidalNeuronAtLayer(2);
            cfg.AddNeuron(2, new SigmoidalNeuron());

            cfg.AddOutputSigmoidalNeuronAtLayer();
            cfg.AddOutputNeuron(new SigmoidalNeuron());

            IList<Pattern> patterns = GetPatterns();

            cfg.SetPatterns(patterns);

            Bpn bpn = cfg.BuildNetwork();

            while(bpn.Propagate()){
                //do something in the middle of the step
            }

            Assert.NotNull(bpn);
        }

        public void ProcedimientoDeLaBPN2() {

            Configuration cfg = new Configuration();

            cfg.SetGlobalError(0.001);
            cfg.SetLearningRate(0.2);
            cfg.SetMomentRate(0.1);
            cfg.SetPatternError(0.001);

            cfg.AddNeuronsAtInput(4); //4 inputs
            cfg.AddHiddenNeuronsAt(1,5,typeof(SigmoidalNeuron)); // 1srt level: 5 neurons
            cfg.AddHiddenNeuronsAt<SigmoidalNeuron>(2, 6); // 2nd level: 5 neurons
            cfg.AddNeuronsAtOutput(5,typeof(SigmoidalNeuron)); //5 Outputs

            IList<Pattern> patterns = GetPatterns();

            cfg.SetPatterns(patterns);

            Bpn bpn = cfg.BuildNetwork();

            while (bpn.Propagate()) {
                //do something in the middle of the step
            }

            Assert.NotNull(bpn);
        }

        private IList<Pattern> GetPatterns() {
            return null;
        }
    }
}

